<?php

namespace app\api\model;

class Mp extends Base
{
    public function UserTbOauth()
    {
        return $this->hasMany(UserReply::class,'uid','id');


    }

    public function add_one_data($name,$user, $appid, $appsecret, $uid)
    {
        $data = $this->create([
            'mp_name' => $name,
            'appid' => $appid,
            'appsecret' => $appsecret,
            'mp_user' => $user,
            'uid' => $uid,
            'valid_token'=>getRandChar(32),
            'encodingaeskey'=>getRandChar(64),
            'state' => 0
        ]);
        if ($data) {
            return ['code' => 1, 'msg' => '添加公众号成功'];
        } else {
            return ['code' => 0, 'msg' => '添加公众号失败'];
        }
    }


    public function del_one_data($id, $uid)
    {
        $data = $this->where('id', $id)->find()->delete();

        if ($data) {
            return ['code' => 1, 'msg' => '删除公众号成功'];
        } else {
            return ['code' => 0, 'msg' => '删除公众号失败'];
        }
    }
    public function edit_one_data($data)
    {
        $data = $this->update($data);

        if ($data) {
            return ['code' => 1, 'msg' => '修改公众号成功'];
        } else {
            return ['code' => 0, 'msg' => '修改公众号失败'];
        }
    }

}